<?php

namespace RTSCraft\MainBundle\Repository;

use Doctrine\ORM\EntityRepository;

class ElementRepository extends EntityRepository
{
  public function findByCategory($n)
  {
    $em = $this->getEntityManager();
    $dql =
      'SELECT e, c ' .
      'FROM RTSCraft\MainBundle\Entity\Element e ' .
      'INNER JOIN e.category c ' .
      "WHERE c.name = '" . $n . "' AND e.deleted = 0";
    $query = $em->createQuery($dql);
    return $query->getResult();
  }
  public function findSheetByStatistic($s_name)
  {
    $em = $this->getEntityManager();
    $dql =
      'SELECT s ' .
      'FROM RTSCraft\MainBundle\Entity\Sheets s ' .
      'INNER JOIN s.statistics stat ' .
      "WHERE stat.name = '" . $s_name . "'";
    $query = $em->createQuery($dql);
    $r = $query->getResult();

    return $r[0];
  }

  public function findPriceByResource($r_name)
  {
    $em = $this->getEntityManager();
    $dql =
      'SELECT p ' .
      'FROM RTSCraft\MainBundle\Entity\Costs c ' .
      'INNER JOIN c.prices p ' .
      'INNER JOIN p.ressource r ' .
      "WHERE r.name = '" . $r_name . "'";
    $query = $em->createQuery($dql);
    $r = $query->getResult();

    return $r[0];
  }

}
?>
